<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $this->verification();
        $this->filecate(1);
        $this->artcate(2);
        $this->albumlist();
        $this->_count();
        $this->display();
    }

    //验证是否登陆
    protected function verification(){
        $userModel=D('user');
        $userinfo=$userModel->where(array('account'=>cookie('account')))->find();
        if(!che() || !$userinfo){
            $url=U('User/login');
            echo "<script>alert('对不起，请您先登陆。');location.href='$url';</script>";
        }
    }

    //获取文件栏目
    protected function filecate($pid){
        $cateModel=D('cate');
        $filecate=$cateModel->gettree($pid);
        $this->assign('filecate',$filecate);
    }

    //获取文章栏目
    protected function artcate($pid){
        $cateModel=D('cate');
        $artcate=$cateModel->gettree($pid);
        $this->assign('artcate',$artcate);
    }

    //获取搜索栏的相册栏目
    protected function albumlist(){
        $albumModel=D('album');
        $albumlist=$albumModel->select();
        $this->assign('albumlist',$albumlist);
    }

    //获取用户、照片、文件、文章的数量(包括回收站)
    protected function _count(){
        $userModel=D('user');
        $picture=D('picture');
        $fileModel=D('file');
        $artModel=D('article');
        $pic_count=$picture->count();
        $file_count=$fileModel->count();
        $user_count=$userModel->count();
        $art_count=$artModel->count();
        $this->assign('users',$user_count);
        $this->assign('pictures',$pic_count);
        $this->assign('files',$file_count);
        $this->assign('articles',$art_count);
    }
}